#include <iostream>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Category.hh>
#include <log4cpp/RollingFileAppender.hh>
using namespace std;
using namespace log4cpp;

void test(){
PatternLayout* ptn1=new PatternLayout();
ptn1->setConversionPattern("%d %c [%p] %m%n");
PatternLayout * ptn2=new PatternLayout();
ptn2->setConversionPattern("%d %c [%p] %m%n");

PatternLayout * ptn3 =new PatternLayout();
ptn3->setConversionPattern("%d %c [%p] %m%n");
//创建输出器对象
OstreamAppender* pos=new OstreamAppender("console",&cout);
//输出器对象跟布局绑定
pos->setLayout(ptn1);
FileAppender * filePos=new FileAppender("file","wd.log");
filePos->setLayout(ptn2);

RollingFileAppender* rhPos=new RollingFileAppender("rollingfile",
                                                    "rollingfile.log"
                                                    ,5*1024,
                                                    3
                                                    );
rhPos->setLayout(ptn3);
//创建日志记录器
Category& salesDepart=Category::getInstance("salesDepart");
//设置日志记录器的优先级
salesDepart.setPriority(Priority::ERROR);
//给Category设置输出器
salesDepart.addAppender(pos);
salesDepart.addAppender(filePos);
salesDepart.addAppender(rhPos);
int count=100;
while(count>0){
    salesDepart.emerg("emerge");
    salesDepart.fatal("fatal");
    salesDepart.alert("alert");
    salesDepart.error("error");
    salesDepart.warn("warn");
    salesDepart.info("info");
    count--;
}
Category::shutdown();
}
int main(int argc, char * argv[]){
    test();
    return 0;
}

